package com.bdqn.t320.ch13.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalException {

    private static final Logger log = LoggerFactory.getLogger(GlobalException.class);

    @ExceptionHandler(value = {ArithmeticException.class})
    public String arithmeticExceptionHandle(Model model, Exception e) {
        model.addAttribute("msg", e.getMessage());
        log.warn("log:" + e.getMessage());
        return "/error/error";
    }

    @ExceptionHandler(value = {Exception.class})
    public String exceptionHandle(Model model, Exception e) {
        model.addAttribute("msg", e.getMessage());
        log.error("log:" + e.getMessage());
        return "/error/error";
    }
}
